﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 易容酒店管理系统
{
    public partial class Room_service : Form
    {
        public Room_service()
        {
            InitializeComponent();
        }
        
        private void Room_service_Load(object sender, EventArgs e)
        {
            ADD();
        }

        private void listView1_Click(object sender, EventArgs e)
        {
            int Index = 0;
            string aa = "";
            if (this.listView1.SelectedItems.Count > 0)//判断listview有被选中项
            {
                Index = this.listView1.SelectedItems[0].Index;//取当前选中项的index,SelectedItems[0]这必须为0
                aa = listView1.Items[Index].SubItems[0].Text;//用我们刚取到的index取被选中的某一列的值从0开始
            }
            string Link = "Server=.;Database=Management_system;integrated security=SSPI;";
            using (SqlConnection con = new SqlConnection(Link))
            {
                string Sql= "select Customer_data.Name,Customer_data.Telephone,Customer_data.requirements from Customer_data,Guest_Room_Number where Guest_Room_Number.RoomID='"+aa+"';";
                using (SqlCommand cmd = new SqlCommand(Sql, con))
                {
                    con.Open();
                    SqlDataReader red = cmd.ExecuteReader();
                    if (red.HasRows)
                    {
                        red.Read();
                        txtName.Text = red[0].ToString();
                        txtTelephone.Text = red[1].ToString();
                        text.Text = red[2].ToString();
                    }
                }
            }
        }
        public void ADD()
        {
            listView1.Items.Clear();
            string Link = "Server=.;Database=Management_system;integrated security=SSPI;";
            SqlConnection con = new SqlConnection(Link);
            string Sql = "select * from GuestInfo";
            SqlDataAdapter add = new SqlDataAdapter(Sql, con);
            DataSet set = new DataSet();
            add.Fill(set, "GuestInfo");
            DataTable table = set.Tables["GuestInfo"];
            for (int i = 0; i < table.Rows.Count; i++)
            {
                DataRow drow = table.Rows[i];
                ListViewItem lvi = new ListViewItem(drow["RoomID"].ToString());
                lvi.SubItems.Add(drow["RoomID"].ToString());
                lvi.SubItems.Add(drow["Type"].ToString());
                lvi.SubItems.Add(drow["GusetInfo"].ToString());
                lvi.SubItems.Add(drow["setting"].ToString());
                lvi.SubItems.Add(drow["Reserve"].ToString());
                listView1.Items.Add(lvi);
            }
        }

        private void listView1_DoubleClick(object sender, EventArgs e)
        {
            int Index = 0;
            if (this.listView1.SelectedItems.Count > 0)//判断listview有被选中项
            {
                Index = this.listView1.SelectedItems[0].Index;//取当前选中项的index,SelectedItems[0]这必须为0
                String aa = listView1.Items[Index].SubItems[0].Text;//用我们刚取到的index取被选中的某一列的值从0开始
                Method.RoomID = aa;
            }
            Money newMoney = new Money();
            newMoney.ShowDialog();
        }
        //返回
        private void button1_Click(object sender, EventArgs e)
        {
            Main_function newzMain_function = new Main_function();

            newzMain_function.TopLevel = false;
            Method.frm.panel1.Controls.Clear();
            Method.frm.panel1.Controls.Add(newzMain_function);
            newzMain_function.Show();
            Method.SetDouble(Method.frm);
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
